package com.android.rapidcash.adapters

import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.android.lib.base.ext.dp2px
import com.android.lib.base.glide.setUrl
import com.android.lib.base.glide.setUrlRound
import com.youth.banner.adapter.BannerAdapter
import com.youth.banner.listener.OnBannerListener


/**
 * author : yzs
 * time   : 2021/07/07
 * desc   : 首页 banner adapter
 */
class BannerImgAdapter(var list: MutableList<String>) : BannerAdapter<String, BannerImgAdapter.VM>(list), OnBannerListener<String> {

    class VM(var imageView: ImageView) : RecyclerView.ViewHolder(
        imageView
    )

    override fun onCreateHolder(parent: ViewGroup, viewType: Int): VM {
        val imageView = ImageView(parent.context)
        //注意，必须设置为match_parent，这个是viewpager2强制要求的
        imageView.layoutParams = ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
        imageView.scaleType = ImageView.ScaleType.CENTER_CROP
        return VM(imageView)
    }

    override fun onBindView(holder: VM, data: String, position: Int, size: Int) {
        holder.imageView.setUrlRound(data,20.dp2px())

    }

    override fun OnBannerClick(data: String, position: Int) {


    }
}